// DeleteDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EEDictionary.h"
#include "DeleteDlg.h"
#include "evdictbase.h"
#include "soundex.h"
#include <string.h>


// DeleteDlg dialog

IMPLEMENT_DYNAMIC(DeleteDlg, CDialog)

DeleteDlg::DeleteDlg(CWnd* pParent /*=NULL*/)
	: CDialog(DeleteDlg::IDD, pParent)
{

}

DeleteDlg::~DeleteDlg()
{
}

void DeleteDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(DeleteDlg, CDialog)
	ON_BN_CLICKED(IDOK, &DeleteDlg::OnBnClickedOk)
END_MESSAGE_MAP()


// DeleteDlg message handlers

void DeleteDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	char* word;
	char* hashCode;
	int address = NOT_FOUND;

	this->UpdateData(TRUE);

	CWnd *tmpCtrl = this->GetDlgItem(IDC_EDIT1);
	CString Cword;
	tmpCtrl->GetWindowText(Cword);

	word = ConvertToChar(Cword);
	_strlwr(word);
	hashCode = soundex(word);
	address = getWordAddress(word, hashCode);
	if (address == (NOT_FOUND))
	{
		CString msg("The word you've entered is not exists!");
		tmpCtrl = this->GetDlgItem(IDC_STATIC1);
		tmpCtrl->SetWindowText(msg);
		return;
	}
	else
	{
		deleteWordFromHashTable(word, hashCode);
		addWordToBackUpList(address);
	}

	this->UpdateData(FALSE);

	OnOK();
}
